package com.hod.reservgrid.client.model;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.gears.client.database.DatabaseException;
import com.google.gwt.user.client.Window;
import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.IntegerFieldDef;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.grid.BaseColumnConfig;
import com.gwtext.client.widgets.grid.ColumnConfig;
import com.gwtext.client.widgets.grid.ColumnModel;
import com.gwtextux.client.data.PagingMemoryProxy;

public class BedTypeGrid extends AbstractGrid {
  
  		    
      private static RecordDef recordDef = new RecordDef(
              new FieldDef[]{  new IntegerFieldDef("idBedType"),
            		          new StringFieldDef("description"), 																	 
              }
      );
  
  	
  
  	public BedTypeGrid() {      
      }
  
      public BedTypeGrid(boolean small,GearsDataStore ds) {
      	this.ds = ds;  
      	columns = new BaseColumnConfig[]{
              //new ColumnConfig("idBedType","idBedType",0, true, null,"idBedType"),
              new ColumnConfig("description","description",0, true, null,"description"),
        };
      	
      	getData();
  
          ColumnModel columnModel = getColumnConfigs();
          setColumnModel(columnModel);
  
          setFrame(true);
          setStripeRows(true);
          setIconCls("grid-icon");
          createPopUp();
          createPager(); 
  
          
      }
      protected void getData(){
      	getData("");
      }
      
      protected void getData(String idRoomType){
      	PagingMemoryProxy proxy = null;
  		try {
  			GearsQuery q = this.ds.getNamedQuery(BedType.FIND_ALL);
  			if (idRoomType.length()>0) q.setString(0, idRoomType);
  			BedType[] data = (BedType[]) q.execute();
  			BedType rs = null;
  			Object[][]data2 = new Object[data.length][];
  			for (int i = 0; i < data.length; i++) {
                  rs = data[i];
                  data2[i] = new Object[]{
                          rs.getIdBedType(),
                          rs.getDescription(),
              };
              }
                          
  			proxy = new PagingMemoryProxy(data2);
  			
  			
  		} catch (DatabaseException e) {
  			// TODO Auto-generated catch block
  			Window.alert(e.getMessage());
  		} 
  
          ArrayReader reader = new ArrayReader(recordDef);
          store = new Store(proxy, reader);
          store.load(0,numberRecords);
          setStore(store);
      }
  
  
}
